/*
 * wbh实习专用，其他人无权访问
 *Practice IntelligenceMajor YCHS 2022
 *努力不一定有回报
 */
package com.wbh.lawyermanager.dongao.controller;

import com.wbh.lawyermanager.dongao.entity.Lawyer;
import com.wbh.lawyermanager.dongao.service.LawyerService;
import com.wbh.lawyermanager.dongao.service.LawyerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.xml.ws.RequestWrapper;
import java.util.List;

/**
 * @author lujingye
 * @version 1.0
 * 律师控制器
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    @RequestMapping("/modify")
    public String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
        //return "../static/success";
        return "redirect:/show";
    }

    @RequestMapping("/getLawyer")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyerById(lawyerid);
        // 把查询得到的lawyer对象保存起来，传递到网页上
        model.addAttribute("lawyer", lawyer);
        return "../static/modifyLawyer";
    }

    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        return "../static/success";
    }
    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        //把lawyerList传递到网上
        model.addAttribute("lawList",lawyerList);
        //displayLawyer代表网页
        return "../static/displayLawyer";
    }
    @RequestMapping("/delLawyer")
    public String deleteLawyer(int lawyerid){
        lawyerService.cancelLawyer(lawyerid);
        return "../static/success";
    }
}

package com.wbh.lawyermanager;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author lujingye
 * @version 1.0
 */
@SpringBootApplication
public class LawyerManagerApplication {
    public static void main(String[] args) {
        SpringApplication.run(LawyerManagerApplication.class, args);
    }
}

package com.wbh.lawyermanager;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class LawyerManagerApplicationTests {

    @Test
    void contextLoads() {
    }

}

package com.wbh.lawyermanager.dongao.mapper;

import com.wbh.lawyermanager.dongao.entity.Lawyer;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @author lujingye
 * @version 1.0
 * 对律师档案的操作：注册档案、删除.. 查询.. 修改..
 */
@Mapper
public interface LawyerMapper {
    /**
     * 修改律师
     * @param lawyer 律师对象，包含律师的全部信息
     * @return 修改成功返回1；否则返回0
     */
    public int updateLawyer(Lawyer lawyer);
    /**
     * 按编号查询律师
     * @param lawyerid 律师编号
     * @return 查询得到的律师对象
     */
    public Lawyer selectLawyerById(int lawyerid);
    /**
     * 添加律师（创建律师档案）
     * @param lawyer 包含律师信息的对象
     * @return 创建成功返回1，否则返回0
     */
    public int insertLawyer(Lawyer lawyer);

    /**
     * 查询所有律师
     * @return 返回律师集合
     */
    public List<Lawyer> selectLawyer();

    /**
     * 删除律师
     * @param lawyerid 律师编号
     * @return 成功返回1，否则0
     */
    public int delLawyer(int lawyerid);
}

package com.wbh.lawyermanager.dongao.service;

import com.wbh.lawyermanager.dongao.entity.Lawyer;

import java.util.List;

/**
 * @author lujingye
 * @version 1.0
 * 律师档案业务接口
 */
public interface LawyerService {
    /**
     * 修改律师
     * @param lawyer 律师对象
     * @return 修改成功返回1，否则返回0
     */
    public int modifyLawyer(Lawyer lawyer);
    /**
     * 按编号查询律师
     * @param lawyerid 律师编号
     * @return 查询得到的律师对象
     */
    public Lawyer findLawyerById(int lawyerid);
    /**
     * 添加律师
     * @param lawyer 律师对象
     * @return 成功返回1，否则0
     */
    public int addLawyer(Lawyer lawyer);

    /**
     * 查询所有律师
     * @return 返回律师集合
     */
    public List<Lawyer> findLawyer();

    /**
     * 删除律师信息
     * @param lawyerid 律师编号
     * @return 成功返回1，否则0
     */
    public int cancelLawyer(int lawyerid);
}

package com.wbh.lawyermanager.dongao.service;

import com.wbh.lawyermanager.dongao.entity.Lawyer;
import com.wbh.lawyermanager.dongao.mapper.LawyerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lujingye
 * @version 1.0
 */
@Service
public class LawyerServiceImpl implements LawyerService {
    @Autowired(required = false)
    LawyerMapper lawyerMapper;

    /**
     * 修改律师
     *
     * @param lawyer 律师对象
     * @return 修改成功返回1，否则返回0
     */
    @Override
    public int modifyLawyer(Lawyer lawyer) {
        return lawyerMapper.updateLawyer(lawyer);
    }

    /**
     * 按编号查询律师
     *
     * @param lawyerid 律师编号
     * @return 查询得到的律师对象
     */
    @Override
    public Lawyer findLawyerById(int lawyerid) {
        return lawyerMapper.selectLawyerById(lawyerid);
    }

    /**
     * 添加律师
     *
     * @param lawyer 律师对象
     * @return 成功返回1.否则0
     */
    @Override
    public int addLawyer(Lawyer lawyer) {
        return lawyerMapper.insertLawyer(lawyer);
    }

    /**
     * @return 律师集合
     */
    @Override
    public List<Lawyer> findLawyer() {
        return lawyerMapper.selectLawyer();
    }

    /**
     * 删除律师信息
     *
     * @param lawyerid 律师编号
     * @return 成功返回1，否则0
     */
    @Override
    public int cancelLawyer(int lawyerid) {
        return lawyerMapper.delLawyer(lawyerid);
    }
}